
package com.googlecode.cswish.oosearch;

import java.io.Serializable;

/**
 * @author Jerry.Feng Date: 2005-2-27 21:12:27
 * @version $id: $
 */
public class Condition implements Serializable {

	private static final long serialVersionUID = 3689632514595895608L;

	public static final Condition DEFAULT = new Condition();
	public static final String LOGIC_AND = " and ";
	public static final String LOGIC_OR = " or ";
	public static final String COMPARE_EQUAL = "=";
	public static final String COMPARE_LIKE = " like ";
	public static final String COMPARE_AUTO = " auto ";

	// ------------------------- property ---------------------------
	// combine parameter by " and "
	private String logicFlag = LOGIC_AND;

	// compare the parameter according to the object type
	private String compareFlag = COMPARE_AUTO;

//	// combine this property to the end of normal hql
//	private String appendedHQL;
//
//	// combine this property to the end of normal hql parameters
//	private Collection appendedHQLParams;

	private int offset;

	private int size;

	// ------------------------- method ---------------------------
//	public String getAppendedHQL() {
//		return appendedHQL;
//	}
//	public void setAppendedHQL(String appendedHQL) {
//		this.appendedHQL = appendedHQL;
//	}
//	public Collection getAppendedHQLParams() {
//		return appendedHQLParams;
//	}
//	public void addAppendedHQL(String appendedHQL) {
//		if (StringUtils.isNotEmpty(appendedHQL)) {
//			if (StringUtils.isEmpty(this.appendedHQL)) {
//				this.appendedHQL = appendedHQL;
//			} else {
//				if (appendedHQL.startsWith(" order by")) {
//					this.appendedHQL = this.appendedHQL + appendedHQL;
//				} else {
//					this.appendedHQL = '(' + this.appendedHQL + ')' + logicFlag + '(' + appendedHQL + ')';
//				}
//			}
//		}
//	}
//	public void setAppendedHQLParams(Collection appendedHQLParams) {
//		this.appendedHQLParams = appendedHQLParams;
//	}
//	public void addAppendedHQLParams(Collection appendedHQLParams) {
//		if (appendedHQLParams != null) {
//			if (this.appendedHQLParams == null) {
//				this.appendedHQLParams = appendedHQLParams;
//			} else {
//				this.appendedHQLParams.addAll(appendedHQLParams);
//			}
//		}
//	}	
	public String getCompareFlag() {
		return compareFlag;
	}
	public void setCompareFlag(String compareFlag) {
		this.compareFlag = compareFlag;
	}
	public String getLogicFlag() {
		return logicFlag;
	}
	public void setLogicFlag(String logicFlag) {
		this.logicFlag = logicFlag;
	}
	public int getOffset() {
		return offset;
	}
	public void setOffset(int offset) {
		if (offset < 0) {
			offset = 0;
		}
		this.offset = offset;
	}
	public int getSize() {
		return size;
	}
	public void setSize(int size) {
		if (size < 0) {
			size = 0;
		}
		this.size = size;
	}
	
	public Object clone() {
		Condition condition = new Condition();
//		condition.setAppendedHQL(this.appendedHQL);
//		if (this.getAppendedHQLParams() != null) {
//			Collection params = new ArrayList();
//			params.addAll(this.getAppendedHQLParams());
//			condition.setAppendedHQLParams(params);
//		}
		condition.setCompareFlag(this.getCompareFlag());
		condition.setLogicFlag(this.getLogicFlag());
		condition.setOffset(this.getOffset());
		condition.setSize(this.getSize());
		return condition;
	}
}
